package com.realbrand.net.realbrandpay.ui.activity.wallet.order;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.realbrand.net.realbrandpay.R;
import com.realbrand.net.realbrandpay.adapter.CommdityDeailAdapter;
import com.realbrand.net.realbrandpay.base.BaseActivity;
import com.realbrand.net.realbrandpay.bean.OrderGroupBean;
import com.squareup.picasso.Picasso;

import java.text.DecimalFormat;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/5/20.
 */

public class OrderDeailActivity extends BaseActivity {
    @BindView(R.id.orderDeail_tv_addressName)
    TextView orderDeailTvAddressName;
    @BindView(R.id.orderDeail_tv_telephone)
    TextView orderDeailTvTelephone;
    @BindView(R.id.orderDeail_lv)
    ListView orderDeailLv;
    @BindView(R.id.orderDeail_toolbar)
    Toolbar orderDeailToolbar;
    @BindView(R.id.orderDeail_tv_province)
    TextView orderDeailTvProvince;
    @BindView(R.id.orderDeail_tv_city)
    TextView orderDeailTvCity;
    @BindView(R.id.orderDeail_tv_county)
    TextView orderDeailTvCounty;
    @BindView(R.id.orderDeail_tv_detailedAdress)
    TextView orderDeailTvDetailedAdress;
    @BindView(R.id.orderDetail_lv_item_iv_brand)
    ImageView orderDetailLvItemIvBrand;
    @BindView(R.id.orderDetail_lv_item_tv_brandName)
    TextView orderDetailLvItemTvBrandName;
    @BindView(R.id.orderDeail_tv_Name)
    TextView orderDeailTvName;
    @BindView(R.id.orderDeail_tv_address)
    TextView orderDeailTvAddress;


    private CommdityDeailAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        ButterKnife.bind(this);
        orderDeailToolbar.setTitle("");
        orderDeailToolbar.setNavigationIcon(R.mipmap.ic_back);
        setSupportActionBar(orderDeailToolbar);
        orderDeailToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        OrderGroupBean g = (OrderGroupBean) getIntent().getSerializableExtra("deail");
        orderDetailLvItemTvBrandName.setText(g.getList().get(0).getBrandName());
        Picasso.with(this).load(g.getList().get(0).getBrandLog()).into(orderDetailLvItemIvBrand);
        View view = LayoutInflater.from(this).inflate(R.layout.orderdeail_lv_item_foot_layout, null);
        TextView orderDetailLvItemFootTvAllMoney = (TextView) view.findViewById(R.id.orderDetail_lv_item_foot_tv_allMoney);
        TextView orderDetailLvItemFootTvDealNumber = (TextView) view.findViewById(R.id.orderDetail_lv_item_foot_tv_DealNumber);
        TextView orderDetailLvItemFootTvConfirmTime = (TextView) view.findViewById(R.id.orderDetail_lv_item_foot_tv_ConfirmTime);
        TextView orderDetailLvItemFootTvDeliveryTime = (TextView) view.findViewById(R.id.orderDetail_lv_item_foot_tv_DeliveryTime);
        TextView orderDetailLvItemFootTvReceiptTime = (TextView) view.findViewById(R.id.orderDetail_lv_item_foot_tv_ReceiptTime);
        TextView orderDetailLvItemFootTvCarrierId = (TextView) view.findViewById(R.id.orderDetail_lv_item_foot_CarrierId);
        TextView orderDetailLvItemFootTvOddName = (TextView) view.findViewById(R.id.orderDetail_lv_item_foot_OddNumbers);
        LinearLayout orderDetailLvItemFootInearConfirmTime = (LinearLayout) view.findViewById(R.id.orderDetail_lv_item_foot_inear_ConfirmTime);
        LinearLayout orderDetailLvItemFootInearDeliveryTime = (LinearLayout) view.findViewById(R.id.orderDetail_lv_item_foot_inear_DeliveryTime);
        LinearLayout orderDetailLvItemFootInearReceiptTime = (LinearLayout) view.findViewById(R.id.orderDetail_lv_item_foot_inear_ReceiptTime);
        LinearLayout orderDetailLvItemFootInearCarrierId = (LinearLayout) view.findViewById(R.id.orderDetail_lv_item_foot_liner_CarrierId);
        if (g.getList().get(0).getDealType().equals("1")) {//表示是货柜
            orderDeailTvName.setText("智能货柜:");
            orderDeailTvAddress.setText("货柜地址:");
            orderDetailLvItemFootInearDeliveryTime.setVisibility(View.GONE);
            orderDetailLvItemFootInearReceiptTime.setVisibility(View.GONE);
            if (g.getList().get(0).getShelvesAccount().equals("0")) {
                orderDeailTvAddressName.setText("");
            } else {
                orderDeailTvAddressName.setText(g.getList().get(0).getShelvesAccount());
            }
            orderDeailTvCity.setVisibility(View.GONE);
            orderDeailTvTelephone.setVisibility(View.GONE);
            orderDeailTvCounty.setVisibility(View.GONE);
            orderDeailTvDetailedAdress.setVisibility(View.GONE);
            if (g.getList().get(0).getWorkAddress().equals("0")) {
                orderDeailTvProvince.setText("");
            } else {
                orderDeailTvProvince.setText(g.getList().get(0).getWorkAddress());
            }
        } else if (g.getList().get(0).getDealType().equals("0")) {//表示是商城
            orderDetailLvItemFootInearDeliveryTime.setVisibility(View.VISIBLE);
            orderDetailLvItemFootInearReceiptTime.setVisibility(View.VISIBLE);
            orderDeailTvName.setText("收货人:");
            orderDeailTvAddress.setText("收货地址:");
            //收货人
            if (g.getList().get(0).getAddressName().equals("0")) {
                orderDeailTvAddressName.setText("");
            } else {
                orderDeailTvAddressName.setText(g.getList().get(0).getAddressName());
            }
            //收货人号码
            if (g.getList().get(0).getTelephone().equals("0")) {
                orderDeailTvTelephone.setText("");
            } else {
                orderDeailTvTelephone.setText(g.getList().get(0).getTelephone());
            }
            //收货人地址
            if (g.getList().get(0).getProvince().equals("0")) {
                orderDeailTvProvince.setText("");
            } else {
                orderDeailTvProvince.setText(g.getList().get(0).getProvince());
            }
            if (g.getList().get(0).getRegionCity().equals("0")) {
                orderDeailTvCity.setText("");
            } else {
                orderDeailTvCity.setText(g.getList().get(0).getRegionCity());
            }
            if (g.getList().get(0).getCountyDistrict().equals("0")) {
                orderDeailTvCounty.setText("");
            } else {
                orderDeailTvCounty.setText(g.getList().get(0).getCountyDistrict());
            }
            if (g.getList().get(0).getDetailedAdress().equals("0")) {
                orderDeailTvDetailedAdress.setText("");
            } else {
                orderDeailTvDetailedAdress.setText(g.getList().get(0).getDetailedAdress());
            }
        }

        adapter = new CommdityDeailAdapter(this, g.getList());
        orderDeailLv.setAdapter(adapter);
        double allMoney = 0.00;
        for (int i = 0; i < g.getList().size(); i++) {
            allMoney += Double.parseDouble(g.getList().get(i).getCommoditySum()) * Double.parseDouble(g.getList().get(i).getCommodityPrice());
        }

        orderDetailLvItemFootTvAllMoney.setText(new DecimalFormat("0.00").format(allMoney));
        orderDetailLvItemFootTvDealNumber.setText(g.getDealNumber());
        orderDetailLvItemFootTvConfirmTime.setText(g.getList().get(0).getConfirmTime());
        orderDetailLvItemFootTvDeliveryTime.setText(g.getList().get(0).getDeliveryTime());
        orderDetailLvItemFootTvReceiptTime.setText(g.getList().get(0).getReceiptTime());
        orderDetailLvItemFootTvCarrierId.setText(g.getList().get(0).getCarrierName());
        if (g.getList().get(0).getOddNumber().equals("0")) {
            orderDetailLvItemFootTvOddName.setText("");
            orderDetailLvItemFootInearCarrierId.setVisibility(View.GONE);
        } else {
            orderDetailLvItemFootTvOddName.setText(g.getList().get(0).getOddNumber());
            orderDetailLvItemFootInearCarrierId.setVisibility(View.VISIBLE);
        }

        if (g.getList().get(0).getDealStatus().equals("2")) {
            orderDetailLvItemFootInearConfirmTime.setVisibility(View.GONE);
            orderDetailLvItemFootInearDeliveryTime.setVisibility(View.GONE);
            orderDetailLvItemFootInearReceiptTime.setVisibility(View.GONE);
        } else if (g.getList().get(0).getDealStatus().equals("3")) {
            orderDetailLvItemFootInearReceiptTime.setVisibility(View.GONE);
            orderDetailLvItemFootInearConfirmTime.setVisibility(View.GONE);
        } else if (g.getList().get(0).getDealStatus().equals("5")) {
            orderDetailLvItemFootInearDeliveryTime.setVisibility(View.GONE);
            orderDetailLvItemFootInearReceiptTime.setVisibility(View.GONE);
        }
        orderDeailLv.addFooterView(view);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.orderdetail_layout;
    }

    @Override
    protected void setOnClick() {

    }

    @Override
    public void onClick(View v) {

    }
}
